package helper

import (
	"github.com/eeppee_admin/clouddisk/service/define"
	"github.com/dgrijalva/jwt-go"
	"errors"
)

// Token解析
func AnalyzeToken(token string) (*define.UserClaim, error) {
	uc := new(define.UserClaim)

	claims, err := jwt.ParseWithClaims(token, uc, func(token *jwt.Token) (any, error){
		return []byte(c.Jwt.SignerKey), nil
	})

	if err != nil {
		return nil, err
	}

	if !claims.Valid {
		return uc, errors.New("Token is invalid")
	}

	return uc, err
}